const Koa = require('koa');
const staticServer = require("koa-static");
const app = new Koa();

const routers_manager = require('./routers/manager');
const views = require('koa-views');
const path = require('path');
const koaBody = require('koa-body');
const mySocket = require('./socket/group');
const myEvent = require('./event/group');
// 使用ctx.body解析中间件
app.use(koaBody());

// 加载模板引擎
app.use(views(path.join(__dirname, './views'), {
    extension: 'ejs'
}));

app.use(staticServer(__dirname));
app
    .use(routers_manager.routes())
    .use(routers_manager.allowedMethods());

let server = require('http').Server(app.callback()),
    io = require('socket.io')(server);

myEvent.startLister();

mySocket.router(io);

console.log("login localhost:5000");
server.listen(5000);